<template>
	<view class="order">
		<mescroll-body @init="mescrollInit" :sticky="true" :down="down" @down="downCallback" @up="upCallback">
			<view class="sticky-tabs">
				<view class="tabbar">
					<!-- <view @click="onTab(0)" :id="tab==0?'select':''">全部<i v-if="tab == 0"></i></view> -->
					<view @click="onTab(5)" :id="tab==5?'select':''">退款({{nums.tuikuan_num}})<i v-if="tab == 5"></i></view>
					<view @click="onTab(6)" :id="tab==6?'select':''">投诉({{nums.tousu_num}})<i v-if="tab == 6"></i></view>
				</view>
				<view class="examine-tab" v-if="tab==5">
					<view @click="change(5)" :class="current==5?'select':''" style="">待审批</view>
					<view @click="change(6)" :class="current==6?'select':''" >已审批</view>
				</view>
				<view class="examine-tab" v-else>
					<view @click="change(7)" :class="current==7?'select':''" style="">待审批</view>
					<view @click="change(8)" :class="current==8?'select':''" >已审批</view>
				</view>
			</view>
			<view class="list">
				<view class="item" v-for="(item,index) in list" :key="index" @click.stop="toDetail(item)">
					<view class="item-inner">
						<view class="name">
							<view class="logo" v-if="item.type == 1">
								<view class="inner-img">
									<image src="https://qiniu-cdn.maeiyun.com/imgs/shangjia/anmo.png"></image>
								</view>
								<text>{{item.title}}</text>
							</view>
							<view class="status" v-if="tab == 5">
								<text v-if="item.return_status == 2">退款待审核</text>
								<text v-if="item.return_status == 3" style="color: #04a257;">商家同意退款/平台待处理</text>
								<text v-if="item.return_status == 4" style="color: #04a257;">已退款</text>
							</view>
							<view style="background-color: #FFE087;color: #DC7500;" v-if="tab == 6" class="status">
								投诉
							</view>
						</view>
						<view class="product" v-if="item.type == 1">
							<image :src="item.images[0]" @error="imageError($event,item)" mode="aspectFill"></image>
							<view class="detail">
								<view class="title">{{item.title}}</view>
								<view class="text">{{item.subscribe_time}}</view>
								<view class="text">总价: <text style="color:#FF0000;">￥{{item.price}}</text></view>
								<view class="text">技师: <text style="color:#333333;">{{item.technician.real_name}}</text></view>
								<!-- <view class="text">退款时间: <text style="color:#333333;">{{item.technician.real_name}}</text></view> -->
							</view>
						</view>
						<view class="bottom-info">
							<view class="user-name">
								<view class="info-lines">
									<text class="title">用户姓名:</text>
									{{item.address.real_name}}
								</view>
								<view class="info-lines" @click="callphone(item.address.mobile)">
									<text class="title">联系方式:</text>
									{{item.address.mobile}}
									<image src="https://qiniu-cdn.maeiyun.com/imgs/shangjia/phone.png" mode=""></image>
								</view>
							</view>
							<view>
								<text class="title">用户地址:</text>	{{item.address.address}}
							</view>
							<view style="margin-top: 10rpx;">
								<text class="title">用户申请时间:</text>	{{item.apply_time}}
							</view>
						</view>
					</view>
					<view class="bottom-btns" v-if="tab == 5 && item.return_status == 2 ">
						<!-- <view class="jie-btn btn" @click.stop="showPopup(1,item)">驳回</view>
						<view class="lines"></view> -->
						<view  class="set-btn btn" style="margin: 0 auto;" @click.stop="showPopup(2,item)">通过</view>
					</view>
				</view>
			</view>
		</mescroll-body>
		<u-modal v-model="show1" show-cancel-button title="" @confirm="dialogConfirm" :content="content">
			<view class="slot-content">
				￥<input type="number" v-model="tuikuanprice" placeholder="输入退款金额" />
			</view>
			<view class="slot-content">
				<input style="margin-left: 1em;" type="text" v-model="tuikuantext" placeholder="输入退款审核备注" />
			</view>
		</u-modal>
		<u-modal v-model="show2" show-cancel-button @confirm="dialogInputConfirm">
			<view class="slot-content">
				<input type="text" v-model="tuikuantext" placeholder="输入驳回理由" />
			</view>
		</u-modal>
		
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				search: '',
				tab: 5,
				list: [],
				isShowBack: false,
				screen: [1, 2, 3, 4], // 筛选结果
				down: {
					auto: false
				},
				page: 1,
				show:false,
				currentOrder:{},
				show1:false,
				show2:false,
				content:"是否同意该退款信息？",
				tuikuanprice:"",
				tuikuantext:"",
				bohuitext:"",
				nums:{},
				current:5
			}
		},
		onShow() {
			this.getNum()
		},
		methods: {
			getNum(){
				var that = this
				this.request.httpTokenRequest({
					url: "store.order/getNotProcessingNum",
					method: "get"
				}, {}).then(function(res) {
					if (res.code == 0) {
						that.nums = res.data
					} else {}
				})
			},
			toDetail(item){
				if(this.tab == 5){
					uni.navigateTo({
						url:'/pages/order/returnMoney?id='+item.id
					})
				}else{
					uni.navigateTo({
						url:'/pages/order/complaint?id='+item.id
					})
				}
				
			},
			showPopup(type,item){
				this.currentOrder = item
				this.tuikuantext = ""
				if(type == 1){ // 
					this.show2 = true
				}else{
					this.show1 = true
				}
			},
			dialogConfirm(){ // 同意
				this.audit(2)
			},
			dialogInputConfirm(){ //驳回
				this.audit(3)
			},
			audit(type){
				var that = this
				this.request.httpTokenRequest({
					url: "store.order/returnPrice",
					method: "post"
				}, {
					order_id:this.currentOrder.id,
					price: this.tuikuanprice,
					store_check_status:type,
					store_check_data:this.tuikuantext,
				}).then(function(res) {
					if (res.code == 0) {
						that.$util.msg(res.msg)
						that.downCallback()
					} else {
						that.$util.msg(res.msg)
					}
					that.tuikuanprice = ""
				})
			},
			callphone(mobile) {
				this.$util.makeCall(mobile)
			},
			handleToSearch() {
				this.downCallback()
			},
			onTab(e) {
				this.tab = e
				if(this.tab == 6){
					this.current = 7
				}else{
					this.current = 5
				}
				this.page = 1
				this.downCallback()
			},
			change(type){
				this.current = type
				this.downCallback()
			},
			goBack() {
				uni.navigateBack()
			},
			downCallback(page) {
				this.list = []
				this.mescroll.resetUpScroll();
			},
			upCallback(page) {
				var that = this
				this.request.httpTokenRequest({
					url: "store.order/getOrderList",
					method: "get"
				}, {
					status: this.current,
					key: ''
				}).then(function(res) {
					if (res.code == 0) {
						that.list = [...that.list, ...res.data.data]
						that.page++
						that.mescroll.endSuccess(that.list.length)
					} else {
						that.mescroll.endErr()
					}
				})
			}

		},
		onLoad(option) {
			if (option.type || option.type === 0) {
				this.tab = option.type
				this.isShowBack = true
			} else {
				this.isShowBack = false
			}
		}
	}
</script>

<style scoped lang="scss">
	.order {
		min-height: 100vh;
		background: #F5F7F8;
		box-sizing: border-box;
	}

	.sticky-tabs {
		z-index: 990;
		position: sticky;
		top: 0;
		background: #F5F7F8;
		// z-index: 1000;
	}

	.nav {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: calc(var(--status-bar-height) + 10px)  30rpx 0 30rpx ;
		// height: 70px;
		width: 100vw;
		background: #F5F7F8;
		z-index: 99;

		.search-content {
			width: 625rpx;
			display: flex;
			align-items: center;

			border-radius: 32rpx;
			border: 1rpx solid #2E7EFA;
			backdrop-filter: blur(10px);
			padding: 7rpx 10rpx 7rpx 23rpx;

			image {
				width: 30rpx;
				height: 30rpx;
				flex: 0 0 auto;
				margin-right: 20rpx;
			}

			input {
				width: 40%;
			}

			.input-placeholder {
				font-size: 28rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #AEAEB0;
			}

			.search-btn {
				width: 103rpx !important;
				height: 50rpx;
				background: #2E7EFA;
				border-radius: 32rpx;
				backdrop-filter: blur(10px);
				font-size: 26rpx;
				line-height: 50rpx;
				text-align: center;
				color: #fff;
				font-family: PingFangSC, PingFang SC;
				margin-left: auto;
			}
		}

		.icon {
			display: flex;
			align-items: center;

			view {
				display: flex;
				align-items: center;
				flex-direction: column;
				margin-left: 30rpx;

				image {
					width: 22rpx;
					height: 24rpx;
				}

				text {
					font-size: 26rpx;
					color: #333333;
					line-height: 37rpx;
				}
			}
		}
	}

	.tabbar {
		padding: 20rpx 32rpx 25rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		background-color: #fff;

		view {
			height: 39rpx;
			font-size: 32rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #000000;
			line-height: 45rpx;
			position: relative;

			i {
				position: absolute;
				bottom: 0;
				left: 10%;
				width: 80%;
				height: 11rpx;
				background:  rgba(46,126,250,0.6);
				border-radius: 4rpx 4rpx 4rpx 4rpx;
			}
		}
	}
	.examine-tab{
		width: 689rpx;
		height: 68rpx;
		border-radius: 34rpx;
		border: 1rpx solid #2E7EFA;
		display: flex;
		align-items: center;
		margin: 20rpx auto;
		overflow: hidden;
		padding: 0;
		view{
			width: 50%;
			height: 100%;
			text-align: center;
			line-height: 68rpx;
			color: #2E7EFA;
		}
		.select{
			background-color: #2E7EFA;
			color: #fff;
		}
	}

	.list {
		padding:10rpx 30rpx 0 30rpx;
		.item {
			background: #FFFFFF;
			border-radius: 10rpx;
			margin-bottom: 30rpx;
			.item-inner{
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 4rpx 4rpx rgba(232,232,232,0.5);
				border-radius: 10rpx;
				padding: 30rpx;
			}
			.name {
				display: flex;
				align-items: flex-start;
				justify-content: space-between;

				.logo {
					display: flex;
					align-items: center;
					.inner-img {
						width: 40rpx;
						height: 40rpx;
						margin-right: 10rpx;
					}

					image {
						width: 40rpx;
						height: 40rpx;
					}

					text {
						font-size: 30rpx;
						font-weight: 400;
						color: #08090A;
						line-height: 42rpx;
						flex-grow: 1;
						width: 80%;
					}
				}

				.status {
					// width: 124rpx;
					padding: 0 20rpx;
					height: 41rpx;
					// background: #FFE7E7;
					border-radius: 4rpx;
					font-size: 26rpx;
					font-weight: 400;
					color: #FF0000;
					line-height: 41rpx;
					text-align: center;
				}
			}

			.product {
				display: flex;
				margin: 30rpx 0 30rpx;

				image {
					width: 142rpx;
					height: 190rpx;
					margin-right: 23rpx;
				}

				.detail {
					flex: 1;

					.title {
						font-size: 28rpx;
						font-weight: 600;
						color: #333333;
						line-height: 40rpx;
					}

					.text {
						font-size: 24rpx;
						color: #656667;
						line-height: 33rpx;
						margin-top: 10rpx;
					}
				}
			}
			.bottom-info{
				background: #F5F7F8;
				border-radius: 10rpx;
				opacity: 0.8;
				padding: 20rpx;
				font-size: 24rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				line-height: 33rpx;
				color: #333333;
				.user-name{
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 10rpx;
					.info-lines{
						image{
							width:22rpx;
							height: 22rpx;
							margin-left: 36rpx;
						}
					}
				}
				text{
					color: #656667 !important;
				}
			}

		}
		
		//
		.bottom-btns{
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 91rpx;
			line-height: 91rpx;
			.btn{
				width:48%;
				text-align: center;
			}
			.jie-btn{
				font-size: 34rpx;
				font-weight: 400;
				color: #949494;
			}
			.set-btn{
				font-size: 34rpx;
				font-weight: 400;
				color: #3393FF;
			}
			.lines{
				width: 1rpx;
				height: 41rpx;
				background-color: #D5D5D5;
			}
		}
	}
	//
	.slot-content {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 10rpx 0;
		input {
			margin: 0;
			text-align: center;
			border-bottom: 1rpx solid #efefef;
			height: 70rpx;
			font-size: 26rpx;
		}
	}
</style>